import time
from common_1.Ultils import ForumDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
class ForumNewpost:
    url=""
    driver=""
    def __init__(self):
        url="http://127.0.0.1:9580/index.html"
        self.driver = ForumDriver.driver
        self.driver.get(url)
    def ForumNewpostTest(self):
        # 等待页面的渲染完成
        Post_button = WebDriverWait(self.driver,15).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post"))
        )
        Post_button.click()
        # 跳转至论坛帖子发布编辑页面
        # 版块
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div.card-body > div:nth-child(1)")
        # 标题
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div.card-body > div:nth-child(2)")
        # 内容
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div.card-body > div:nth-child(3)")
        # 发布按钮
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit")

        # 按键功能检测
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_title").send_keys("NewpostTest")
        # 内容创造编辑
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.editormd-toolbar > div > ul > li:nth-child(13) > a > i").click()
        # 点击发布按钮
        Publish_button = WebDriverWait(self.driver,15).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR,"#article_post_submit"))
        )

        # 滚动元素到视图页面
        actions = ActionChains(self.driver)
        actions.move_to_element(Publish_button).perform()
        # 点击发布
        Publish_button.click()

        time.sleep(5)
        # 在首页是否出现新的帖子
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col")

